<?php
class qrcode extends CI_Controller {
	function index() {
		$this -> pub -> logp('浏览二维码生成', '2');
		$da = $this -> pub -> get_setting('二维码', 'QRcode');
		$q = $this -> db -> get_where('setting');
		$ls = $q -> row_array(0);
		$da['qr'] = unserialize($ls['qrcode']);
		$da['qr_qun'] = unserialize($ls['qrcode_qun']);
		$this -> load -> view('adminx/qrcode', $da);
	}

	function up() {
		$this -> pub -> logp('修改微信二维码参数', '2');
		$da['name_top'] = $this -> input -> post('name_top');
		$da['tx_top'] = $this -> input -> post('tx_top');
		$da['tx_left'] = $this -> input -> post('tx_left');
		$da['tx_k'] = $this -> input -> post('tx_k');
		$da['tx_g'] = $this -> input -> post('tx_g');
		$da['qr_k'] = $this -> input -> post('qr_k');
		$da['qr_g'] = $this -> input -> post('qr_g');
		$da['qr_top'] = $this -> input -> post('qr_top');
		$da['qr_left'] = $this -> input -> post('qr_left');
		$da['qr_bg'] = $this -> input -> post('qr_bg');
		$in['qrcode'] = serialize($da);
		$this -> db -> update('setting', $in);
		echo json_encode(array('type' => 1));
	}
	
	function qun_up() {
		$this -> pub -> logp('修改微信二维码参数', '2');
		$da['name_top'] = $this -> input -> post('name_top');
		$da['tx_top'] = $this -> input -> post('tx_top');
		$da['tx_left'] = $this -> input -> post('tx_left');
		$da['tx_k'] = $this -> input -> post('tx_k');
		$da['tx_g'] = $this -> input -> post('tx_g');
		$da['qr_k'] = $this -> input -> post('qr_k');
		$da['qr_g'] = $this -> input -> post('qr_g');
		$da['qr_top'] = $this -> input -> post('qr_top');
		$da['qr_left'] = $this -> input -> post('qr_left');
		$da['qr_bg'] = $this -> input -> post('qr_bg');
		$in['qrcode_qun'] = serialize($da);
		$this -> db -> update('setting', $in);
		echo json_encode(array('type' => 1));
	}

	//二维码的重新生成
	function re_ewm() {
		ignore_user_abort(true);
		if (!defined('DS')) {
			define('DS', DIRECTORY_SEPARATOR);
		}
		$this -> pub -> logp('重新生成二维码 - ' . $this -> input -> post('idx'), '1-2');
		@unlink(FCPATH . 'upfiles' . DS . 'member' . DS . $this -> config -> item('qrcode_pay') . DS . $this -> input -> post('idx') . '.jpg');
		$back=$this -> pub -> haibao($this -> input -> post('idx'));
		echo json_encode(array('type' => $back['type'], 'src' => '/upfiles/member/' . $this -> config -> item('qrcode_pay') . '/' . $this -> input -> post('idx') . '.jpg'));
	}
	
	function qun_re_ewm() {
		ignore_user_abort(true);
		if (!defined('DS')) {
			define('DS', DIRECTORY_SEPARATOR);
		}
		$this -> pub -> logp('重新生成二维码 - ' . $this -> input -> post('idx'), '1-2');
		@unlink(FCPATH . 'upfiles' . DS . 'member' . DS . $this -> config -> item('qrcode_pay') . DS . $this -> input -> post('idx') . '.jpg');
		
		$q=$this->db->get_where('co_main',array('id'=>$this -> input -> post('idx')));
		$m=$q->row_array(0);
		
		$q=$this->db->get_where('member',array('mid'=>$m['mid']));
		$mm=$q->row_array(0);
		
		$back=$this -> pub -> haibao_qun($m,$mm);
		echo json_encode(array('type' => $back['type'], 'src' => '/upfiles/member/' . $this -> config -> item('qrcode_pay') . '/' . $this -> input -> post('idx') . '_qun.jpg'));
	}

	//更新全部二维码
	function re_all() {
		$this -> pub -> logp('更新全部二维码', '2');
		$this -> load -> helper('file');
		delete_files('./upfiles/member/' . $this -> config -> item('qrcode_pay') . '/');
		echo json_encode(array('type' => 1));
	}

}
?>